﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ImmovablesManager
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class Login : Window
    {
        public static string Role;
        public static Guid UserId;
        public static string UserName;
        public bool IsCorrect;
        public Login()
        {
            InitializeComponent();
        }

        public void CheckUser()
        {
            var user = AppController.ImmoRepository.GetUserByLoginPassword(TBxUserName.Text, TBxPassword.Password);
            if (user == null) {IsCorrect = false;}
            else
            {
                IsCorrect = true;
                Role = user.UserRole;
                UserId = user.UserId;
                UserName = user.UserFirstName + " " + user.UserLastName;
            }
        }

        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            CheckUser();
            if(!IsCorrect)
            {
                MessageBox.Show("Неверный пользователь или пароль", "Ошибка!");
            }
            else
            {
                Close();
            }
            
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }


    }
}
